package work5;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.annotation.Resources;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"./app.xml"})
public class Test {
	
	@Autowired
	@Qualifier("userServiceImpl")
	UserService userService;
	
	@Resource(name="orderServiceImpl")
	OrderService orderService;
	
	@org.junit.Test
	public void t1() {
		//根据id查询用户
		List<Integer> list=new ArrayList<>();
		list.add(1);
		list.add(10);
		List<User> users = userService.getUserById(list);
		for(User u : users) {
			System.out.println(u);
		}
		//用户名模糊查询
		List<User> userByUserName = userService.getUserByUserName("张");
		for(User u : userByUserName) {
			System.out.println(u);
		}
		PageHelper page=new PageHelper();
		page.setPagesize(5);//必须先设置尺寸
		page.setStart(2);//因为start做运算
		List<User> pageInfo=userService.getUserPagination(page);
		for(User u: pageInfo) {
			System.out.println(u);
		}
	}
	
	@org.junit.Test
	public void t2() {
		 User user=new User();
		 user.setId(46);
		 user.setAddress("郑州市");
		 int flag = userService.updUserById(user);
		 if(flag==1) {
			 System.out.println("修改成功");
			 List<Integer> list=new ArrayList();
			 list.add(user.getId());
			 System.out.println("修改结果如下\n"+userService.getUserById(list));
		 }else {
			 System.out.println("修改失败");
		 }
	}
	
	@org.junit.Test
	public void t3() {
		User user=new User();
		 user.setAddress("郑州市");
		 user.setSex("女");
		 user.setUsername("秦可卿");
		 Date date = new Date();
		 user.setBirthday(date);
		 int flag = userService.insertUser(user);
		 if(flag==1) {
			 System.out.println("添加成功");
			 List<Integer> list=new ArrayList();
			 list.add(user.getId());
			 System.out.println("添加结果如下\n"+userService.getUserById(list));
		 }else {
			 System.out.println("添加失败");
		 }
	}
	
	@org.junit.Test
	public void t4() {
		//根据订单号查询用户信息
		Order order = orderService.getUserByOrderNumber("1000010");
		System.out.println(order);
		//根据用户名查询订单信息
		List<User> userWithOrder = userService.getOrdersByUserName("六帅");
		for(User s:userWithOrder) {
			System.out.println(s);
		}
		//根据用户名查询商品信息
		List<User> userWithItem = userService.getItemByUserName("六帅");
		for(User s:userWithItem) {
			System.out.println(s);
		}
	}
	 
}
